function [ placetobomb ] = bomberm( vectorofpositions,lag )
%UNTITLED Summary of this function goes here
%   Inputs: Matrix 2xn p, the first line represents the x-values and the
%   second line represents the y values of each postition of the ship.
p=fliplr(vectorofpositions);
n=max(size(p));

%Use all the values to predict
%The lenght is euclidian distance
%The angles use the x axis as reference
for i=1:1:n-1
    x1=p(1,i);
    y1=p(2,i);
    x2=p(1,i+1);
    y2=p(2,i+1);
    %lengthvector(i)=sqrt((x2-x1)^2+(y2-y1)^2);
    
    if(x2==x1)
        if(y2>y1)
            anglex(i) = pi/2;
        else
            anglex(i) = 3*pi/2;
        end
    else
        if(x2>x1)
            anglex(i)=atan((y2-y1)/(x2-x1));
        else
            anglex(i)=atan((y2-y1)/(x2-x1))+pi;
        end
    end
end

%Change the angles to have the last vector as reference:
for i=1:n-2
    anglerelative(i)=anglex(i+1)-anglex(i);
end

%Calculating the "placetobomb" using hmm;
%finallength=mean(lengthvector);
finalangle=hiddenMarkovBomber(anglerelative, lag);

%To make it easy, we will use the x axis again as reference:
finalangle(1)=finalangle(1)+anglex(n-1);
if lag>1
    for i=2:1:lag
        finalangle(i)=finalangle(i)+finalangle(i-1);
    end
end

placetobomb=[x2,y2];

for i=1:1:lag;
    placetobomb=placetobomb+[cos(finalangle(i)),sin(finalangle(i))];
end

